package cn.doitedu.datayiee.rest.dao;

import cn.doitedu.datayiee.rest.pojo.GroupByResultBean;
import cn.doitedu.datayiee.rest.utils.KylinUtil;
import org.springframework.stereotype.Repository;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

@Repository
public class KylinGroupByDaoImpl implements KylinGroupByDao {
    @Override
    public List<GroupByResultBean> queryGroupBy(String sql) {
        try {

            Connection connection = KylinUtil.getKylinConnection();

            PreparedStatement statement = connection.prepareStatement(sql);

            ResultSet resultSet = statement.executeQuery();

            ArrayList<GroupByResultBean> groupByResultBeans = new ArrayList<>();
            while (resultSet.next()) {
                String province = resultSet.getString(1);
                String city = resultSet.getString(2);
                String region = resultSet.getString(3);
                long session_cnt = resultSet.getLong(4);
                long pv_amt = resultSet.getLong(5);
                GroupByResultBean bean = new GroupByResultBean();
                bean.setProvince(province);
                bean.setCity(city);
                bean.setRegion(region);
                bean.setSessionCnt(session_cnt);
                bean.setPvAmt(pv_amt);

                groupByResultBeans.add(bean);
            }


            resultSet.close();
            statement.close();
            connection.close();

            return groupByResultBeans;

        } catch (Exception e) {
            e.printStackTrace();
        }


        return null;
    }
}
